#include "runner/base_runner.hpp"
#include "camera/mjpeg_camera.hpp"
#include "buffer/shared_frame_buffer.hpp"


class MJPEGCameraRunner : public RunnerBase {
    public:
        MJPEGCameraRunner(MJPEGCamera &camera, std::shared_ptr<SharedFrameBuffer> buffer)
            : RunnerBase("CameraRunner"), _camera(camera), _buffer(std::move(buffer)) {}
    
    protected:
        void Run() override {
            while (IsRunning()) {
                if (_camera.UpdateFrame()) {
                    _buffer->SetFrame(_camera.GetFrame());
                }
                std::this_thread::sleep_for(std::chrono::milliseconds(30)); // 控制帧率
            }
        }
    
    private:
        MJPEGCamera &_camera;
        std::shared_ptr<SharedFrameBuffer> _buffer;
    };
    